﻿/*
英文A+B 
Time Limit:1000MS  Memory Limit:32768K

  
Description:
输入两个小于100的正整数A和B，计算A+B。
注意：A和B的每一个数字由对应的英文单词组成。

Input:
测试输入包含若干测试用例，每个测试用例占一行，格式为"A + B ="，相邻两字符串有一个空格间隔。
当A和B同时为zero时输入结束，相应的结果不要输出. 
Output:
对每个测试用例输出1行，即A+B的值. 
Sample Input:
one + two =
three four + five six =
seven + eight nine =
one two + two zero =
zero + zero =
Sample Output:
3
90
96
32
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
static const char* numbers[]={
"zero","one","two","three","four",
"five","six","seven","eight","nine"
};
const unsigned M=17;
unsigned hashes[M];

unsigned hash(const char* str)
{
	if(NULL==str)
		return 5U;

	unsigned code=0U;
	for (const char* p=str; *p; ++p)
	{
		code=code*13+ *p-'a';
	}
	return code%M;
}

unsigned toNumber(char * str)
{
	unsigned result=0U;
	char *part1=strtok(str, " ");
	if(NULL!=part1)
	{
		char *part2=strtok(NULL, " ");
		result=hashes[hash(part1)];
		if(NULL!=part2)
			result=result*10+hashes[hash(part2)]; 
	}
	return result;
}
int main()
{
	for (unsigned i=0, n=sizeof(numbers)/sizeof(numbers[0]); i<n; i++)
	{
		hashes[hash(numbers[i])]=i;
//		printf("%u, %u\n",hash(numbers[i]),i );
	}

	char expr[64];
	
	while (gets(expr))
	{
		char *part1=strtok(expr, "+=");
		char *part2=strtok(NULL,"+=");
		unsigned num1 = toNumber(part1);
		unsigned num2 = toNumber(part2);
		if(0==num1 && 0==num2)
			break;

		printf("%u\n",  num1+num2);
	}

	return EXIT_SUCCESS;
}